package su.fishr.effects 
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.filters.GlowFilter;
	import flash.filters.BevelFilter;
	
	
	/**
	 * ...
	 * @private
	 * @author fish_r
	 */
	public class BevelsAndGlow extends EventDispatcher
	{
		public const END_APPLY_EFFECT:String = "endAppleEffect";
		
		private var _dObject:DisplayObject;
		private var _glowFilter:GlowFilter;
		private var _bevelFilter:BevelFilter;
		private var _alpha:Number = 1;
		private var _distance:Number = 0 ;
		private var _flagGlow:Boolean = false;
		private var _strength:Number = 0;
		
		public function set distance(value:Number):void 
		{
			_distance = value;
		}
		
		public function set strength(value:Number):void 
		{
			_strength = value;
		}
		
		public function BevelsAndGlow(target:IEventDispatcher = null) 
		{
			
		}
		
		public function addFilter(obj:DisplayObject):void
		{
			_dObject = obj;
			
			
			_dObject.addEventListener(Event.ENTER_FRAME, enterFrameListener);
			
		}
		
		private function enterFrameListener(e:Event):void 
		{
			
			_glowFilter  = new GlowFilter(0xFFFFFF, _alpha, _distance, _distance, _strength);
			_bevelFilter = new BevelFilter(1, 45, 0xFFCCCC);
			_dObject.filters = [_bevelFilter];// , _glowFilter ];
			///_dObject.filters = [_glowFilter];
			
			if ( _flagGlow ) {
				_distance -= .1;
				_strength -= .002;
			}
			else
			{
				_distance += .5 ;
				_strength += .01 ;
			}
			
			if ( _distance >= 40 ) _flagGlow = true;
			
				if (_distance < 20 )
				{
					_dObject.removeEventListener(Event.ENTER_FRAME, enterFrameListener);

					dispatchEvent ( new Event( END_APPLY_EFFECT ) );
					return;
				}

			
			
			///_alpha += .05;
			
		}
		
		
		
	}

}